home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga News 95
/
Amiga News 95.iso
/
dpat
/
dpat48
/
dearch
/
sources
/
archiwindow2.c
next >
Wrap
C/C++ Source or Header
|
1993-11-14
|
11KB
|
363 lines
/*
* ArchiWindow2.c
*
*/
#include <exec/types.h>
#include <exec/lists.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/imageclass.h>
#include <intuition/gadgetclass.h>
#include <libraries/gadtools.h>
#include <libraries/amigaguide.h>
#include <graphics/displayinfo.h>
#include <graphics/gfxbase.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/gadtools_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#ifdef __SASC
#include <pragmas/exec_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/gadtools_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#include <pragmas/utility_pragmas.h>
#endif
#include <string.h>
#define CATCOMP_NUMBERS
#include "ArchiWindow2.h"
#include "PrefsWindow.h"
#include "CrunchPrefs.h"
#include "local_dearch.h"
#include "dearchguide.h"
#include "dearch_strings.h"
BOOL ArchiGadget00Clicked( void );
BOOL ArchiGadget10Clicked( void );
BOOL ArchiGadget20Clicked( void );
BOOL ArchiGadget30Clicked( void );
BOOL ArchiGadget40Clicked( void );
BOOL ArchiGadget50Clicked( void );
BOOL ArchiGadget60Clicked( void );
BOOL ArchiGadget70Clicked( void );
void HandleArchiIDCMP( void );
BOOL OpenArchiWindow( void );
BOOL CloseArchiWindow( void );
extern BOOL OpenPrefsWindow(void);
struct Window *ArchiWnd = NULL;
static struct Gadget *ArchiGList = NULL;
static struct IntuiMessage ArchiMsg;
struct Gadget *ArchiGadgets[8];
static UWORD ArchiLeft = 82;
static UWORD ArchiTop = 38;
static UWORD ArchiWidth = 423;
static UWORD ArchiHeight = 178;
BOOL addflag;
struct crunch *nodecmd;
char *oldoption, *oldext;
BOOL oldrep;
static UWORD ArchiGTypes[] = {
STRING_KIND,
LISTVIEW_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND,
BUTTON_KIND
};
static struct NewGadget ArchiNGad[] = {
68, 100, 258, 16, NULL, NULL, GD_ArchiGadget00, 0, NULL, (APTR)ArchiGadget00Clicked,
68, 22, 258, 74, NULL, NULL, GD_ArchiGadget10, PLACETEXT_ABOVE|NG_HIGHLABEL, NULL, (APTR)ArchiGadget10Clicked,
296, 153, 92, 19, NULL, NULL, GD_ArchiGadget20, PLACETEXT_IN, NULL, (APTR)ArchiGadget20Clicked,
296, 127, 92, 19, NULL, NULL, GD_ArchiGadget30, PLACETEXT_IN, NULL, (APTR)ArchiGadget30Clicked,
164, 152, 92, 19, NULL, NULL, GD_ArchiGadget40, PLACETEXT_IN, NULL, (APTR)ArchiGadget40Clicked,
22, 126, 92, 19, NULL, NULL, GD_ArchiGadget50, PLACETEXT_IN, NULL, (APTR)ArchiGadget50Clicked,
22, 152, 92, 19, NULL, NULL, GD_ArchiGadget60, PLACETEXT_IN, NULL, (APTR)ArchiGadget60Clicked,
164, 127, 92, 19, NULL, NULL, GD_ArchiGadget70, PLACETEXT_IN, NULL, (APTR)ArchiGadget70Clicked
};
static ULONG ArchiGTags[] = {
(GTST_MaxChars), 256, (STRINGA_Justification), (GACT_STRINGCENTER), (TAG_DONE),
(GTLV_Labels), NULL, GTLV_Top, 8, (GTLV_ShowSelected), NULL, (GTLV_Selected), 0, (TAG_DONE),
(GT_Underscore), '_', (TAG_DONE),
(GT_Underscore), '_', (TAG_DONE),
(GT_Underscore), '_', (TAG_DONE),
(GT_Underscore), '_', (TAG_DONE),
(GT_Underscore), '_',(TAG_DONE),
(GT_Underscore), '_', (TAG_DONE)
};
extern struct Library *GadToolsBase, *UtilityBase, *IntuitionBase;
extern struct Window *PrefsWnd;
extern struct List myList;
extern struct Gadget *PrefsGadgets[5];
extern struct Screen *Scr;
extern APTR VisualInfo;
extern struct TextAttr topaz8;
void HandleArchiIDCMP( void )
{
struct IntuiMessage *m;
BOOL (*func)();
BOOL running = TRUE;
while( (running) && (m = GT_GetIMsg( ArchiWnd->UserPort)) )
{
CopyMem(( char * )m, ( char * )&ArchiMsg, (long)sizeof( struct IntuiMessage ));
GT_ReplyIMsg( m );
switch ( ArchiMsg.Class )
{
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh( ArchiWnd );
GT_EndRefresh( ArchiWnd, TRUE );
break;
case IDCMP_CLOSEWINDOW:
running = CloseArchiWindow();
break;
case IDCMP_GADGETUP:
func = ( void * )(( struct Gadget * )ArchiMsg.IAddress )->UserData;
running = func();
break;
case IDCMP_VANILLAKEY:
switch (ArchiMsg.Code)
{
case 'a':
case 'A':
running = ArchiGadget50Clicked();
break;
case 'e':
case 'E':
running = ArchiGadget70Clicked();
break;
case 'o':
case 'O':
running = CloseArchiWindow();
break;
case 's':
case 'S':
running = ArchiGadget30Clicked();
break;
case 'u':
case 'U':
running = ArchiGadget40Clicked();
break;
case 'v':
case 'V':
running = ArchiGadget60Clicked();
break;
}
case IDCMP_RAWKEY:
if (ArchiMsg.Code == 95)
running = HandleGadgetHelp(&ArchiMsg);
break;
}
}
}
BOOL OpenArchiWindow( void )
{
struct NewGadget ng;
struct Gadget *g;
struct TagItem *tmp;
UWORD lc, tc;
UWORD offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
LocaliseGadgets(ArchiNGad, Archi_CNT, MSG_ARCHIGAD00);
if ( ! ( g = CreateContext( &ArchiGList )))
return( FALSE );
for( lc = 0, tc = 0; lc < Archi_CNT; lc++ ) {
CopyMem((char * )&ArchiNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
ng.ng_VisualInfo = VisualInfo;
ng.ng_TextAttr = &topaz8;
ng.ng_LeftEdge += offx;
ng.ng_TopEdge += offy;
if ( ArchiGTypes[ lc ] == LISTVIEW_KIND )
{
if ( tmp = FindTagItem( GTLV_ShowSelected, ( struct TagItem * )&ArchiGTags[ tc]))
tmp->ti_Data = (ULONG)ArchiGadgets[GD_ArchiGadget00 - 9];
}
ArchiGadgets[ lc ] = g = CreateGadgetA((ULONG)ArchiGTypes[ lc ], g, &ng, ( struct TagItem * )&ArchiGTags[ tc ] );
while( ArchiGTags[ tc ] ) tc += 2;
tc++;
if ( ! g )
return( FALSE );
}
if (!IsListEmpty(&myList))
{
GT_SetGadgetAttrs(ArchiGadgets[GD_ArchiGadget10 - 9], ArchiWnd, NULL,
GTLV_Labels, ~0,
TAG_END);
GT_SetGadgetAttrs(ArchiGadgets[GD_ArchiGadget10 - 9], ArchiWnd, NULL,
GTLV_Labels, &myList,
TAG_END);
}
if ( ! ( ArchiWnd = OpenWindowTags( NULL,
WA_Left, ArchiLeft,
WA_Top, ArchiTop,
WA_Width, ArchiWidth,
WA_Height, ArchiHeight + offy,
WA_IDCMP, STRINGIDCMP|LISTVIEWIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_VANILLAKEY|IDCMP_RAWKEY,
WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
WA_Gadgets, ArchiGList,
WA_Title, GetString(&li, MSG_TITLE_ARCHIWINDOW),
WA_CustomScreen, Scr,
TAG_DONE )))
return( FALSE );
GT_RefreshWindow( ArchiWnd, NULL );
return( TRUE );
}
BOOL CloseArchiWindow( void )
{
if ( ArchiWnd ) {
CloseWindow( ArchiWnd );
ArchiWnd = NULL;
}
if ( ArchiGList ) {
FreeGadgets( ArchiGList );
ArchiGList = NULL;
}
return FALSE;
}
BOOL ArchiGadget00Clicked( void )
{
return TRUE;
}
BOOL ArchiGadget10Clicked( void )
{
return TRUE;
}
BOOL ArchiGadget20Clicked( void )
{
CloseArchiWindow();
return FALSE;
}
BOOL ArchiGadget30Clicked( void )
{
struct crunch *cmd;
if (cmd = (struct crunch *)FindName(&myList, (STRPTR)GetGadString(ArchiGadgets[GD_ArchiGadget00 - 9])))
{
Remove((struct Node *)cmd);
FreeVec(cmd);
GT_SetGadgetAttrs(ArchiGadgets[GD_ArchiGadget10 - 9], ArchiWnd, NULL,
GTLV_Labels, ~0,
TAG_END);
GT_SetGadgetAttrs(ArchiGadgets[GD_ArchiGadget10 - 9], ArchiWnd, NULL,
GTLV_Labels, &myList,
TAG_END);
}
return TRUE;
}
BOOL ArchiGadget40Clicked( void )
{
SavePrefs(UseFile);
CloseArchiWindow();
return FALSE;
}
BOOL ArchiGadget50Clicked( void )
{
if (nodecmd = AllocVec(sizeof(struct crunch), MEMF_CLEAR))
{
nodecmd->cr_Node.ln_Name = strdup(GetGadString(ArchiGadgets[GD_ArchiGadget00 - 9]));
if ( (!FindName(&myList,GetGadString(ArchiGadgets[GD_ArchiGadget00 - 9]))) && (strlen(nodecmd->cr_Node.ln_Name) > 0))
{
if (PrefsWnd == NULL)
{
addflag = OpenPrefsWindow();
}
}
else
FreeVec(nodecmd);
}
return TRUE;
}
BOOL ArchiGadget60Clicked( void )
{
SavePrefs(SaveFile);
SavePrefs(UseFile);
CloseArchiWindow();
return FALSE;
}
BOOL ArchiGadget70Clicked( void )
{
addflag = FALSE;
if (nodecmd = (struct crunch *)FindName(&myList, GetGadString(ArchiGadgets[GD_ArchiGadget00 - 9])))
{
if (PrefsWnd == NULL)
{
if (OpenPrefsWindow())
{
GT_SetGadgetAttrs(PrefsGadgets[GD_PrefsGadget20 - 17], PrefsWnd, NULL,
GTST_String, nodecmd->cr_ext);
GT_SetGadgetAttrs(PrefsGadgets[GD_PrefsGadget30 - 17], PrefsWnd, NULL,
GTST_String, nodecmd->cr_option);
GT_SetGadgetAttrs(PrefsGadgets[GD_PrefsGadget40 - 17], PrefsWnd, NULL,
GTCB_Checked, nodecmd->cr_rep);
oldoption = strdup(nodecmd->cr_option);
oldext = strdup(nodecmd->cr_ext);
oldrep = nodecmd->cr_rep;
}
}
}
return TRUE;
}